package com.quhaodian.plug.data.service.impl;

import com.quhaodian.plug.api.SendCodePlugin;
import com.quhaodian.plug.data.service.CodeService;
import com.quhaodian.plug.data.service.PluginService;

import javax.annotation.Resource;
import java.util.Map;


public class CodeServiceImpl implements CodeService {

    @Resource(name = "pluginServiceImpl")
    private PluginService pluginService;

    private Map<String, String> attrs;

    public Map<String, String> getAttrs() {
        return attrs;
    }

    public void setAttrs(Map<String, String> attrs) {
        this.attrs = attrs;
    }

    @Override
    public boolean sendCode(String code, String template, String phone) {
        for (SendCodePlugin plugin : pluginService.getSendCodePlugins(true)) {
            String xtemplate = template;
            if (attrs != null) {
                xtemplate = attrs.get(template);
            }
            plugin.sendCode(code, "", "", xtemplate, phone);

        }
        return true;
    }
}
